<template>
    <view class="content">
        <view class="item" v-for="(item, index) in list" :key="index">
            <view class="title">报销日期：{{item.date}}</view>
            <view class="title">金额：<text class="price">￥{{item.money}}</text></view>
            <view class="title">报销人员：{{item.name}}</view>
            <view class="title">报销描述：</view>
            <view class="text">
                {{item.describes}}
            </view>
            <view class="img-box">
                <image :src="el.image" class="img" v-for="(el, ind) in item.images" :key="ind" @click="doPreview(item.images, ind)"></image>
            </view>
            <!-- status：1未报销 2已报销 -->
            <view class="btns" v-if="item.status == 1">
                <view class="btn" @click="$gTo(`/pages/pay/pay?id=${item.id}&money=${item.money}`)">立即支付</view>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
            };
        },
        onShow() {
            this.page = 1
            this.list = []
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            //预览照片
            doPreview(item, index) {
                let arr = []
                item.forEach(cur => {
                    arr.push(cur.image)
                })
                uni.previewImage({
                    urls: arr,
                    current: index,
                    longPressActions: {
                        success: function(data) {
                        },
                        fail: function(err) {
                        }
                    }
                });
            },
            
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('reimbursement', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail && ret.detail.reimbursement && ret.detail.reimbursement.length > 0) {
            				this.list = this.list.concat(ret.detail.reimbursement);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    page{
        background-color: #f5f5f5;
    }
    .content{
        padding: 20rpx;
    }
    .item{
        padding: 35rpx;
        margin-bottom: 20rpx;
        background-color: #fff;
        border-radius: 15rpx;
        font-size: 24rpx;
    }
    .title{
        font-weight: bold;
        padding-bottom: 10rpx;
    }
    .price{
        font-size: 28rpx;
        color: #f62a2a;
    }
    .text{
        color: #8f8f8f;
    }
    .img-box{
        padding-top: 20rpx;
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-start;
        align-items: center;
    }
    .img{
        width: 148rpx;
        height: 148rpx;
        border-radius: 10rpx;
        margin-right: 10rpx;
        margin-bottom: 10rpx;
    }
    .btns{
        padding-top: 10rpx;
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
    .btn{
        padding: 15rpx 25rpx;
        font-size: 28rpx;
        color: #fff;
        background-color: #f29700;
        border-radius: 15rpx;
    }

</style>
